package com.wzh.navcode.service.impl;

import com.wzh.navcode.domain.entity.HotData;
import com.wzh.navcode.factory.CrawlStrategyFactory;
import com.wzh.navcode.service.CrawlStrategy;
import com.wzh.navcode.service.HotDataSearchService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @Author: wangzh
 * @Version: 1.0
 * @Description:
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class HotDataSearchServiceImpl implements HotDataSearchService {

    private final CrawlStrategyFactory strategyFactory;

    @Override
    public List<HotData> crawlHotData(String platform) {
        try {
            CrawlStrategy strategy = strategyFactory.getStrategy(platform);
            return strategy.crawl();
        } catch (Exception e) {
            log.error("爬取失败: {}", platform, e);
            return Collections.emptyList();
        }
    }
}
